<style lang="less">
    @import '../../styles/common.less';
    @import '../tables/components/table.less';
</style>
<template>
    <div>
        <Card shadow style="margin-top: 10px;">
            <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="220">
                <Row :gutter="16">
                    <Col span="12" >
                    <FormItem label="矿机锁仓本金释放比率(%)" prop="releaseRate">
                        <Input v-model="formValidate.releaseRate" placeholder="请输入百分比"></Input>
                    </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="矿机动态收益可兑换积分比率(%)" prop="integralRate">
                        <Input v-model="formValidate.integralRate" placeholder="请输入百分比"></Input>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="16">
                    <Col span="12" >
                    <FormItem label="矿机是否开启收益计算" prop="isStartCalculateEarnings">
                        <Select v-model="formValidate.isStartCalculateEarnings" placeholder="请选择是否开启">
                            <Option value="1">开启</Option>
                            <Option value="0">关闭</Option>
                        </Select>
                    </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="矿机提取释放本金比率(%)" prop="outflowFee">
                        <Input v-model="formValidate.outflowFee" placeholder="请输入百分比"></Input>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="16">
                    <Col span="12">
                    <FormItem label="矿机签到开始时间" prop="ct">
                        <TimePicker  v-model="formValidate.ct"  :value="formValidate.ct"  placeholder="请选择开始时间" style="width: 168px"></TimePicker>
                    </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="矿机签到结束时间" prop="st">
                        <TimePicker  v-model="formValidate.st" :value="formValidate.st"   placeholder="请选择结束时间" style="width: 168px"></TimePicker>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="16">
                    <Col span="12" >
                    <FormItem label="矿机静态提取到锁仓AITC比率(%)" prop="staticOutLockaitcRate">
                        <Input v-model="formValidate.staticOutLockaitcRate" placeholder="请输入百分比"></Input>
                    </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="矿机静态提取到释放AITC比率(%)" prop="staticOutUnlockaitcRate">
                        <Input v-model="formValidate.staticOutUnlockaitcRate" placeholder="请输入百分比"></Input>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="16">
                    <Col span="12" >
                    <FormItem label="矿机动态提取到锁仓AITC比率(%)" prop="dynamicOutLockaitcRate">
                        <Input v-model="formValidate.dynamicOutLockaitcRate" placeholder="请输入百分比"></Input>
                    </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="	矿机动态提取到释放AITC比率(%)" prop="dynamicOutUnlockaitcRate">
                        <Input v-model="formValidate.dynamicOutUnlockaitcRate" placeholder="请输入百分比"></Input>
                    </FormItem>
                    </Col>
                </Row>
                <FormItem>
                    <Button type="primary" @click="handleSubmit('formValidate')">提交</Button>
                </FormItem>
            </Form>
        </Card>
    </div>
</template>
<script>
    import $http from '../../utils/axiosWrap'
    import Cookies from 'js-cookie'

    export default {
        data () {
            var validatePass = (rule,value, callback) => {
                setTimeout(() => {
                    if (value < 0 || value >100) {
                        callback(new Error('请输入0-100数字'));
                    } else {
                        callback();
                    }
                }, 1000);
            };
            return {
                formValidate: {
                    releaseRate: '',
                    integralRate: '',
                    isStartCalculateEarnings: '',
                    outflowFee: '',
                    id:'',
                    ct:'',
                    st:'',
                    staticOutLockaitcRate:'',
                    staticOutUnlockaitcRate:'',
                    dynamicOutLockaitcRate:'',
                    dynamicOutUnlockaitcRate:''
                },
                ruleValidate: {
                    releaseRate: [
                        { required: true, message: '矿机锁仓本金释放比率不得为空', trigger: 'blur' },
                        { validator: validatePass, trigger: 'blur' }
                    ],
                    integralRate: [
                        { required: true, message: '矿机动态收益可兑换积分比率不得为空', trigger: 'blur' },
                        { validator: validatePass, trigger: 'blur' }
                    ],
                    isStartCalculateEarnings: [
                        { required: true, message: '矿机是否开启收益计算不得为空', trigger: 'blur' }
                    ],
                    outflowFee: [
                        { required: true, message: '矿机提取释放本金比率不得为空', trigger: 'blur' },
                        { validator: validatePass, trigger: 'blur' }
                    ],
                    ct: [
                        { required: true, message: '矿机签到开始时间不得为空', trigger: 'blur' },
                        { validator: validatePass, trigger: 'blur' }
                    ],
                    st: [
                        { required: true, message: '矿机签到结束时间不得为空', trigger: 'blur' },
                        { validator: validatePass, trigger: 'blur' }
                    ],
                    staticOutLockaitcRate: [
                        { required: true, message: '矿机静态提取到锁仓AITC比率不得为空', trigger: 'blur' },
                        { validator: validatePass, trigger: 'blur' }
                    ],
                    staticOutUnlockaitcRate: [
                        { required: true, message: '矿机静态提取到释放AITC比率不得为空', trigger: 'blur' },
                        { validator: validatePass, trigger: 'blur' }
                    ],
                    dynamicOutLockaitcRate: [
                        { required: true, message: '矿机动态提取到锁仓AITC比率不得为空', trigger: 'blur' },
                        { validator: validatePass, trigger: 'blur' }
                    ],
                    dynamicOutUnlockaitcRate: [
                        { required: true, message: '矿机动态提取到释放AITC比率不得为空', trigger: 'blur' },
                        { validator: validatePass, trigger: 'blur' }
                    ]
                },
                Message: ''
            }
        },
        created(){
            this.load()
        },
        methods: {
            handleSubmit (name) {
                var _this = this
                _this.formValidate.releaseRate += ''
                _this.formValidate.integralRate += ''
                _this.formValidate.outflowFee += ''

                let date = new Date(_this.formValidate.ct);
                var month = date.getMonth() + 1
                var day =  date.getDate()
                var hours =   date.getHours()
                var minutes = date.getMinutes()
                var datese = date.getSeconds()
                if(datese /1  < 10){
                    datese = '0' +  datese
                }
                if(month /1  < 10){
                    month = '0' +  month
                }
                if(day /1  < 10){
                    day = '0' +  day
                }
                if(hours /1  < 10){
                    hours = '0' +  hours
                }
                if(minutes /1  < 10){
                    minutes = '0' +  minutes
                }
                _this.formValidate.ct =  hours + ':' + minutes + ':' + datese
                date =  hours + ':' + minutes + ':' + datese
                let dates = new Date(_this.formValidate.st);
                var months = dates.getMonth() + 1
                var days =  dates.getDate()
                var hourss =   dates.getHours()
                var minutess = dates.getMinutes()
                var datases = dates.getSeconds()
                if(datases /1  < 10){
                    datases = '0' +  datases
                }
                if(months /1  < 10){
                    months = '0' +  months
                }
                if(days /1  < 10){
                    days = '0' +  days
                }
                if(hourss /1  < 10){
                    hourss = '0' +  hourss
                }
                if(minutess /1  < 10){
                    minutess = '0' +  minutess
                }
                _this.formValidate.st = hourss + ':' + minutess + ':' + datases;
                dates =  hourss + ':' + minutess + ':' + datases;
                if((_this.formValidate.staticOutLockaitcRate / 1 + _this.formValidate.staticOutUnlockaitcRate / 1) == 100){
                    if((_this.formValidate.dynamicOutLockaitcRate / 1 + _this.formValidate.dynamicOutUnlockaitcRate / 1 ) == 100){
                        _this.formValidate.staticOutLockaitcRate += ''
                        _this.formValidate.staticOutUnlockaitcRate += ''
                        _this.formValidate.dynamicOutLockaitcRate += ''
                        _this.formValidate.dynamicOutUnlockaitcRate += ''
                        _this.$refs[name].validate((valid) => {
                            if (valid) {
                                let params = new URLSearchParams()
                                params.append('releaseRate',_this.formValidate.releaseRate)
                                params.append('integralRate',_this.formValidate.integralRate)
                                params.append('outflowFee',_this.formValidate.outflowFee)
                                params.append('isStartCalculateEarnings',_this.formValidate.isStartCalculateEarnings)
                                params.append('id',_this.formValidate.id)
                                params.append('updateName',Cookies.get('user'))
                                params.append('startTime',_this.formValidate.ct)
                                params.append('endTime',_this.formValidate.st)
                                params.append('staticOutLockaitcRate',_this.formValidate.staticOutLockaitcRate)
                                params.append('staticOutUnlockaitcRate',_this.formValidate.staticOutUnlockaitcRate)
                                params.append('dynamicOutLockaitcRate',_this.formValidate.dynamicOutLockaitcRate)
                                params.append('dynamicOutUnlockaitcRate',_this.formValidate.dynamicOutUnlockaitcRate)

                                $http.post('/oreAllModules/updateOreRule',params).then(function (res) {
                                    if(res.suc){
                                        _this.$Message.success('修改成功!')
                                        _this.load()
                                    }else{
                                        if(res.msg == "请先登录"){
                                            _this.$Message.error('请重新登录！');
                                        }else{
                                            _this.$Message.error(res.msg);
                                        }
                                    }
                                })
                            }
                        })
                    }else{
                        _this.$Message.error('矿机动态提取到锁仓AITC比率 + 矿机动态提取到释放AITC比率 必须等于 100');
                    }
                }else{
                    _this.$Message.error('矿机静态提取到锁仓AITC比率 + 矿机静态提取到释放AITC比率 必须等于 100');
                }
            },
            handleReset (name) {
                this.$refs[name].resetFields();
            },
            load () {
                let _this = this
                let params = new URLSearchParams()
                $http.post('/oreAllModules/getOreRule',params).then(function (res) {
                 if(res.suc){
                    _this.formValidate.releaseRate = res.result.releaseRate * 100 +''
                    _this.formValidate.integralRate = res.result.integralRate * 100 + ''
                    _this.formValidate.outflowFee = res.result.outflowFee * 100 + ''
                    _this.formValidate.isStartCalculateEarnings = res.result.isStartCalculateEarnings + ''
                    _this.formValidate.id = res.result.id + ''
                    _this.formValidate.ct = res.result.signInStartTime
                    _this.formValidate.st = res.result.signInEndTime
                     _this.formValidate.staticOutLockaitcRate = res.result.staticOutLockaitcRate * 100 +''
                     _this.formValidate.staticOutUnlockaitcRate = res.result.staticOutUnlockaitcRate * 100 +''
                     _this.formValidate.dynamicOutLockaitcRate = res.result.dynamicOutLockaitcRate * 100 +''
                     _this.formValidate.dynamicOutUnlockaitcRate = res.result.dynamicOutUnlockaitcRate * 100 +''
                }else{
                    if(res.msg == "请先登录"){
                        _this.$Message.error('请重新登录！');
                    }else{
                        _this.$Message.error(res.msg);
                    }
                }
                })
            }
        }
    };
</script>
<style>

</style>
